package com.esms.esmsadmin.controller.system.basic;
import com.esms.esmsadmin.entity.MenuEntity;
import com.esms.esmsadmin.entity.RespBean;
import com.esms.esmsadmin.entity.RoleEntity;
import com.esms.esmsadmin.entity.StudentEntity;
import com.esms.esmsadmin.service.MenuService;
import com.esms.esmsadmin.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/system/basic/perm")
public class PermController {
    @Autowired
    RoleService roleService;
    @Autowired
    MenuService menuService;
    @GetMapping("/")
    public List<RoleEntity> getAllRoles(){
        return roleService.getAllRoles();
    }
    @GetMapping("/menus")
    public List<MenuEntity> getAllMenus(){
        return menuService.getAllMenus();
    }

    @GetMapping("/mids/{rid}")
    public List<Integer> getMidsByRid(@PathVariable Integer rid){
        return menuService.getMidsByRid(rid);
    }

    @PutMapping("/")
    public RespBean updateMenuRole(Integer rid, Integer []mids){
        if(menuService.updateMenuRole(rid,mids)){
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @PutMapping("/role")
    public RespBean insertRole(@RequestBody RoleEntity roleEntity){
        if(roleService.insertRole(roleEntity) == 1){
            return RespBean.ok("添加角色成功");
        }
        return RespBean.error("添加角色失败");
    }
}
